package com.one.consumer.user.ui;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.utils.ClickUtils;
import com.one.common.utils.StringUtils;
import com.one.common.view.base.IView;
import com.one.common.view.widget.InputLayout;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseActivityC;
import com.one.consumer.R;
import com.one.consumer.user.model.extra.InvoiceExtra;
import com.one.consumer.user.model.item.LookUpItem;
import com.one.consumer.user.presenter.InvoicePresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/11/3 9:19 PM
 * description ：索取发票 从保修订单详情过来
 **/
@Route(path = RouterPath.ADD_INVOICE)
public class AddInvoiceActivity extends BaseActivityC<InvoicePresenter> implements IView {
    @BindView(R.id.il_company_name)
    InputLayout ilCompanyName;
    @BindView(R.id.il_company_no)
    InputLayout ilCompanyNo;
    @BindView(R.id.il_company_address)
    InputLayout ilCompanyAddress;
    @BindView(R.id.il_company_phone)
    InputLayout ilCompanyPhone;
    @BindView(R.id.il_company_bank)
    InputLayout ilCompanyBank;
    @BindView(R.id.il_company_bank_account)
    InputLayout ilCompanyBankAccount;
    @BindView(R.id.ll_company)
    LinearLayout llCompany;
    @BindView(R.id.il_name)
    InputLayout ilName;
    @BindView(R.id.il_invoice_content)
    InputLayout ilInvoiceContent;
    @BindView(R.id.il_invoice_money)
    InputLayout ilInvoiceMoney;
    @BindView(R.id.il_contact)
    InputLayout ilContact;
    @BindView(R.id.il_phone)
    InputLayout ilPhone;
    @BindView(R.id.il_address)
    InputLayout ilAddress;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;

    /**
     * 默认抬头
     */
    private LookUpItem defaultLookUp;
    /**
     * 发票金额
     */
    private InvoiceExtra invoiceExtra;

    @Override
    protected void initPresenter() {
        mPresenter = new InvoicePresenter(this, this);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_add_invoice;
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("索取发票");
    }



    @Override
    public void initView() {
        super.initView();
        invoiceExtra = (InvoiceExtra) getIntent().getSerializableExtra(InvoiceExtra.getExtraName());
        ilInvoiceMoney.getTvCenter().setTextColor(Color.parseColor("#F5A623"));
        if (invoiceExtra != null && StringUtils.isNotBlank(invoiceExtra.getMoney())) {
            ilInvoiceMoney.setText(invoiceExtra.getMoney());
        }
        ilInvoiceContent.setText("技术费");
        setDefaultLookUp(invoiceExtra.getLookUpItem());
    }

    @OnClick(R.id.tv_submit)
    public void submit() {
        if(ClickUtils.isFastClick())return;
        mPresenter.submitInvoice(ilContact.getText(),
                ilPhone.getText(), ilAddress.getText());
    }

    /**
     * 设置抬头
     */
    public void setDefaultLookUp(LookUpItem item) {
        if (defaultLookUp == null) {
            defaultLookUp = item;
        }
        if (item.getInvoice_type().equals("1")) { // 个人
            ilName.setVisibility(View.VISIBLE);
            llCompany.setVisibility(View.GONE);
            ilName.setText(item.getInvoice_name());
        } else { // 企业
            ilName.setVisibility(View.GONE);
            llCompany.setVisibility(View.VISIBLE);
            ilCompanyName.setText(item.getInvoice_company_name());
            ilCompanyAddress.setText(item.getInvoice_company_address());
            ilCompanyBank.setText(item.getInvoice_bank_name());
            ilCompanyBankAccount.setText(item.getInvoice_bank_no());
            ilCompanyPhone.setText(item.getInvoice_company_phone());
            ilCompanyNo.setText(item.getInvoice_no());

        }
    }

}
